<?php
class ConstModel extends model
{
	static $_instance = null;

	static function getInstance ()
	{
		if (is_null(self::$_instance)) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	// 取得常量组
	function ConstGroup()
	{
		return $this->sql("select * from sys_keyword order by id")->s();
	}
	
	// 取得常量值
	function ConstValue($p)
	{
		return $this->sql("select * from sys_keyword_value where gid = [gid] order by id",$p)->s();
	}
	
	// 增加常量值
	function ConstValueAdd($p)
	{
		return $this->sql("insert into sys_keyword_value(`gid`,`val`,`name`)values('[gid]','[val]','[name]')",$p)->i();
	}
	
	// 修改常量值
	function ConstValueUpd($p)
	{
		return $this->sql("update sys_keyword_value set `name`='[name]',`val`='[val]' where `id`='[id]'",$p)->u();
	}
	
	// 删除机构
	function ConstValueDel($p)
	{
		return $this->sql("delete from sys_keyword_value where `id`='[id]'",$p)->u();
	}
	
	// 分组数组
	function ConstGroupValue()
	{
		$return = array();
		$rs = $this->sql("select gid,val as id,name from sys_keyword_value")->s();
		foreach ($rs as $item){
			$return[$item["gid"]][] = $item;
		}
		return $return;
	}
}